/*
 * Filename:    Dm_Hcpms_Ew_Org_Kpi_D_F.java
 * Copyright:   2015 中国平安保险（集团）股份有限公司 版权所有
 * Company:     平安科技养老险及健康险系统开发部
 * Create at:   2015-3-5
 */
package com.paic.mhis.hcpms.etlhcpms.job.biz.service.impl;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.paic.mhis.hcpms.etlhcpms.job.biz.service.DmHcpmsEwOrgKpiDFService;
import com.paic.mhis.hcpms.etlhcpms.job.dto.HcpmsBiEtlBatchDTO;
import com.paic.mhis.hcpms.etlhcpms.job.dto.HcpmsBiEtlBatchLog;
import com.paic.mhis.hcpms.etlhcpms.job.intergration.dao.DmHcpmsEwOrgKpiDFDAO;
import com.paic.mhis.hcpms.quota.calculationreport.calculationjob.biz.service.KpiJobCtrlService;
import com.paic.mhis.hcpms.quota.calculationreport.calculationjob.constants.CalculationJobConstants;
import com.paic.mhis.hcpms.quota.calculationreport.calculationjob.dto.HcpmsKpiJobCtrlDTO;
import com.pingan.um.client.util.UUID;

/**
 * 计算 医保定点机构费用预警分析报表 数据实现类
 * 
 * @author EX-FUYANGMING001
 */
@Component("dmHcpmsEwOrgKpiDFServiceImpl")
public class DmHcpmsEwOrgKpiDFServiceImpl implements DmHcpmsEwOrgKpiDFService {

	public static final int ROWS = 5000;
	public static Log log = LogFactory.getLog(DmHcpmsEwOrgKpiDFServiceImpl.class);
	@Autowired
	private DmHcpmsEwOrgKpiDFDAO dmHcpmsEwOrgKpiDFDAO;
	@Autowired
	private KpiJobCtrlService kpiJobCtrlService;

	@Override
	public void processIndicatorsCalculation() {

		HcpmsKpiJobCtrlDTO ctrlDto = new HcpmsKpiJobCtrlDTO();
		ctrlDto.setJobCode("J20150309005");
		ctrlDto.setJobName("ETL数据同步JOB");
		ctrlDto.setJobStatus(CalculationJobConstants.CTRL_JOB_STATUS_USE);
		ctrlDto.setTmpId(UUID.getID());
		ctrlDto = kpiJobCtrlService.getHcpmsJobCtrl(ctrlDto);

		if (ctrlDto == null) {
			log.info("-----没有可计算的ETL数据或者JOB被占用-----");
			return;
		}

		log.info("-----------ETL数据准备阶段job进入 跑批次差集--------");
		dmHcpmsEwOrgKpiDFDAO.insertqueryEtlBatchMinusInfo();
		log.info("-----------ETL数据准备阶段job进入 跑批次差集--------");

		Date startDate = new Date();
		log.info("-----医保定点机构费用预警分析报表START-----" + startDate);
		Map<String, String> map = new HashMap<String, String>();
		map.put("status", "00");
		map.put("isvalid", "0");
		List<HcpmsBiEtlBatchDTO> listhbe = dmHcpmsEwOrgKpiDFDAO.selectHcpmsBiEtlBatchList(map);
		if (null != listhbe && listhbe.size() > 0) {

			// 医疗机构数据同步
			log.info("-----ETL医疗机构数据同步 开始-----");
			dmHcpmsEwOrgKpiDFDAO.insertDmHcpmsMedicalOrgD();
			log.info("-----ETL医疗机构数据同步 结束-----");

			// 科室同步数据
			log.info("-----ETL科室同步数据 开始-----");
			dmHcpmsEwOrgKpiDFDAO.insertDmHcpmsMedicalDeptD();
			log.info("-----ETL科室同步数据 结束-----");

			Map<String, String> pczt = null;
			for (HcpmsBiEtlBatchDTO dto : listhbe) {
				try {
					pczt = new HashMap<String, String>();
					pczt.put("idEtlBatch", dto.getIdEtlBatch());
					// 状态(00未处理 01抽取中 02抽取完成 20抽取失败)
					pczt.put("status", "01");

					log.info("-----修改 etl 批次数据 状态-----");
					dmHcpmsEwOrgKpiDFDAO.updateDmHcpmsEwBct1KpiMF(pczt);

					log.info("-----医疗与医保定点机构费用预警分析报表 JOB 计算开始-----");
					addDmHcpmsEwOrgKpiDFDto(dto);
					log.info("-----医疗与医保定点机构费用预警分析报表 JOB 计算结束-----");

					log.info("-----医疗与医保发票项目预警表 JOB 计算开始-----");
					addDmHcpmsEwBct1KpiMF(dto);
					log.info("-----医疗与医保发票项目预警表 JOB 计算结束-----");

					log.info("-----医疗与医保药品预警表 JOB 计算开始-----");
					addDmHcpmsEwBpt2KpiMF(dto);
					log.info("-----医疗与医保药品预警表 JOB 计算结束-----");

					log.info("-----发票费用类型与FWA审核对照 JOB 计算开始-----");
					addDmHcpmsEwBct1AssMF(dto);
					log.info("-----发票费用类型与FWA审核对照 JOB 计算结束-----");

					log.info("-----药品费用与FWA审核对照  JOB 计算开始-----");
					addDmHcpmsEwBpt2AssMF(dto);
					log.info("-----药品费用与FWA审核对照  JOB 计算结束-----");

					log.info("-----医保总费用和处方数  JOB 计算开始-----");
					addDMHcpmsEwAssCfMF(dto);
					log.info("-----医保总费用和处方数  JOB 计算开始-----");

					log.info("-----BI报表数据项统计信息表  JOB 计算开始-----");
					addDmBiAllKpiValues(dto);
					log.info("-----BI报表数据项统计信息表  JOB 计算开始-----");

					log.info("-----修改 BI报表数据项统计信息表的住院天数  JOB 计算开始-----");
					updateDmBiAllKpiValuesHospitolDay(dto);
					log.info("-----修改 BI报表数据项统计信息表的住院天数  JOB 计算开始-----");

					log.info("-----机构和科室基础指标表  JOB 计算开始-----");
					addDmHcpmsEwProtocOrgKpiF(dto);
					log.info("-----机构和科室基础指标表  JOB 计算开始-----");

				} catch (Exception e) {

					log.info("etl 批次数据 循环 错误 " + e.getMessage());
					pczt.put("status", "20");
					dmHcpmsEwOrgKpiDFDAO.updateDmHcpmsEwBct1KpiMF(pczt);
				}
			}

		}
		ctrlDto.setJobStatus(CalculationJobConstants.CTRL_JOB_STATUS_IDLE);
		ctrlDto.setTmpId(null);
		kpiJobCtrlService.updateHcpmsJobCtrl(ctrlDto);
	}

	/****
	 * 添加医保定点机构费用预警分析报表
	 * 
	 * @param dto
	 * @throws ParseException
	 */
	private void addDmHcpmsEwOrgKpiDFDto(HcpmsBiEtlBatchDTO dto) {

		HcpmsBiEtlBatchLog obj = new HcpmsBiEtlBatchLog();
		obj.setBatchNo(dto.getBatchNo());
		obj.setOpertionName("医疗与医保定点机构费用预警分析报表JOB");
		obj.setOpertionDesc("医疗与医保定点机构费用预警分析报表JOB");

		Map<String, String> pczt = new HashMap<String, String>();
		pczt.put("idEtlBatch", dto.getIdEtlBatch());
		// 状态(00未处理 01抽取中 02抽取完成 20抽取失败)
		pczt.put("status", "20");
		int count = 0;

		try {

			dmHcpmsEwOrgKpiDFDAO.insertDmHcpmsEwOrgKpiDFDtoYl(getStrDateAndEndDate(dto, "10001", null, null));
			dmHcpmsEwOrgKpiDFDAO.insertDmHcpmsEwOrgKpiDFDtoYb(getStrDateAndEndDate(dto, "10002", null, null));

		} catch (Exception e) {
			count++;
			obj.setStatus("02");// 失败
			obj.setExceptionMessage("报异常:" + e.getMessage());
			log.info("医疗与医保定点机构费用预警分析报表JOB 计算错误 " + e.getMessage());
		} finally {
			dmHcpmsEwOrgKpiDFDAO.insertEtlBatchJobLogDTO(obj);
			if (count > 0) {
				dmHcpmsEwOrgKpiDFDAO.updateDmHcpmsEwBct1KpiMF(pczt);
			}
		}
	}

	/****
	 * 添加医保定点机构费用预警分析报表
	 * 
	 * @param dto
	 * @throws ParseException
	 */
	private void addDmHcpmsEwBct1KpiMF(HcpmsBiEtlBatchDTO dto) {

		HcpmsBiEtlBatchLog obj = new HcpmsBiEtlBatchLog();
		obj.setBatchNo(dto.getBatchNo());
		obj.setOpertionName("医疗与医保发票项目预警表JOB");
		obj.setOpertionDesc("医疗与医保发票项目预警表JOB");

		Map<String, String> pczt = new HashMap<String, String>();
		pczt.put("idEtlBatch", dto.getIdEtlBatch());
		// 状态(00未处理 01抽取中 02抽取完成 20抽取失败)
		pczt.put("status", "20");
		int count = 0;
		try {

			dmHcpmsEwOrgKpiDFDAO.insertDmHcpmsEwBct1KpiMFYl(getStrDateAndEndDate(dto, "10001", null, null));
			dmHcpmsEwOrgKpiDFDAO.insertDmHcpmsEwBct1KpiMFYb(getStrDateAndEndDate(dto, "10002", null, null));

		} catch (Exception e) {
			count++;
			obj.setStatus("02");// 失败
			obj.setExceptionMessage("报异常:" + e.getMessage());
			log.info("医疗与医保发票项目预警表JOB 计算错误 " + e.getMessage());
		} finally {
			dmHcpmsEwOrgKpiDFDAO.insertEtlBatchJobLogDTO(obj);
			if (count > 0) {
				dmHcpmsEwOrgKpiDFDAO.updateDmHcpmsEwBct1KpiMF(pczt);
			}
		}
	}

	/****
	 * 添加药品预警表
	 * 
	 * @param dto
	 * @throws ParseException
	 */
	private void addDmHcpmsEwBpt2KpiMF(HcpmsBiEtlBatchDTO dto) {

		HcpmsBiEtlBatchLog obj = new HcpmsBiEtlBatchLog();
		obj.setBatchNo(dto.getBatchNo());
		obj.setOpertionName("医疗与医保药品预警表 JOB");
		obj.setOpertionDesc("医疗与医保药品预警表 JOB");

		Map<String, String> pczt = new HashMap<String, String>();
		pczt.put("idEtlBatch", dto.getIdEtlBatch());
		// 状态(00未处理 01抽取中 02抽取完成 20抽取失败)
		pczt.put("status", "20");
		int count = 0;

		try {
			// 增加先计算某月的高价和贵重的项目编号的code
			dmHcpmsEwOrgKpiDFDAO.insertHcpmsHightAmountProject(getStrDateAndEndDate(dto, null, null, null));

			dmHcpmsEwOrgKpiDFDAO.insertDmHcpmsEwBpt2KpiMFYl(getStrDateAndEndDate(dto, "10001", null, null));
			dmHcpmsEwOrgKpiDFDAO.insertDmHcpmsEwBpt2KpiMFYb(getStrDateAndEndDate(dto, "10002", null, null));

			// 基本药物 数据
			dmHcpmsEwOrgKpiDFDAO.insertDmHcpmsEwBpt2KpiMFYlJBYW(getStrDateAndEndDate(dto, "10001", null, null));
			dmHcpmsEwOrgKpiDFDAO.insertDmHcpmsEwBpt2KpiMFYbJBYW(getStrDateAndEndDate(dto, "10002", null, null));
			// 限用药品 住院 数据
			dmHcpmsEwOrgKpiDFDAO.insertDmHcpmsEwBpt2KpiMFYbXYYPzy(getStrDateAndEndDate(dto, "10002", null, null));
			// 限用药品 门诊 数据
			dmHcpmsEwOrgKpiDFDAO.insertDmHcpmsEwBpt2KpiMFYbXYYPmz(getStrDateAndEndDate(dto, "10002", null, null));

			// 贵重药品
			dmHcpmsEwOrgKpiDFDAO.insertDmHcpmsEwBpt2KpiMFYlGJGZ(getStrDateAndEndDate(dto, "10001", null, null));

			// 门诊 医疗贵重药品
			dmHcpmsEwOrgKpiDFDAO.insertDmHcpmsEwBpt2KpiMFMZYlGJGZ(getStrDateAndEndDate(dto, "10002", null, null));
			// 门诊 医保贵重药品
			dmHcpmsEwOrgKpiDFDAO.insertDmHcpmsEwBpt2KpiMFMZYbGJGZ(getStrDateAndEndDate(dto, "10002", null, null));

		} catch (Exception e) {
			count++;
			obj.setStatus("02");// 失败
			obj.setExceptionMessage("报异常:" + e.getMessage());
			log.info("医疗与医保药品预警表 JOB 计算错误 " + e.getMessage());
		} finally {
			dmHcpmsEwOrgKpiDFDAO.insertEtlBatchJobLogDTO(obj);
			if (count > 0) {
				dmHcpmsEwOrgKpiDFDAO.updateDmHcpmsEwBct1KpiMF(pczt);
			}
		}
	}

	/****
	 * 添加 发票费用类型与FWA审核对照
	 * 
	 * @param dto
	 * @throws ParseException
	 */
	private void addDmHcpmsEwBct1AssMF(HcpmsBiEtlBatchDTO dto) {

		HcpmsBiEtlBatchLog obj = new HcpmsBiEtlBatchLog();
		obj.setBatchNo(dto.getBatchNo());
		obj.setOpertionName("发票费用类型与FWA审核对照 JOB");
		obj.setOpertionDesc("发票费用类型与FWA审核对照 JOB");

		Map<String, String> pczt = new HashMap<String, String>();
		pczt.put("idEtlBatch", dto.getIdEtlBatch());
		// 状态(00未处理 01抽取中 02抽取完成 20抽取失败)
		pczt.put("status", "20");
		int count = 0;
		try {

			dmHcpmsEwOrgKpiDFDAO.insertDmHcpmsEwBct1AssMFDjdbyj(getStrDateAndEndDate(dto, null, null, null));

		} catch (Exception e) {
			count++;
			obj.setStatus("02");// 失败
			obj.setExceptionMessage("报异常:" + e.getMessage());
			log.info("发票费用类型与FWA审核对照 JOB 计算错误 " + e.getMessage());
		} finally {
			dmHcpmsEwOrgKpiDFDAO.insertEtlBatchJobLogDTO(obj);
			if (count > 0) {
				dmHcpmsEwOrgKpiDFDAO.updateDmHcpmsEwBct1KpiMF(pczt);
			}
		}
	}

	/****
	 * 添加 药品费用与FWA审核对照
	 * 
	 * @param dto
	 * @throws ParseException
	 */
	private void addDmHcpmsEwBpt2AssMF(HcpmsBiEtlBatchDTO dto) {

		HcpmsBiEtlBatchLog obj = new HcpmsBiEtlBatchLog();
		obj.setBatchNo(dto.getBatchNo());
		obj.setOpertionName("药品费用与FWA审核对照  JOB");
		obj.setOpertionDesc("药品费用与FWA审核对照  JOB");

		Map<String, String> pczt = new HashMap<String, String>();
		pczt.put("idEtlBatch", dto.getIdEtlBatch());
		// 状态(00未处理 01抽取中 02抽取完成 20抽取失败)
		pczt.put("status", "20");
		int count = 0;
		try {

			dmHcpmsEwOrgKpiDFDAO.insertDmHcpmsEwBpt2AssMFDjdbyj(getStrDateAndEndDate(dto, null, null, null));

		} catch (Exception e) {
			count++;
			obj.setStatus("02");// 失败
			obj.setExceptionMessage("报异常:" + e.getMessage());
			log.info("药品费用与FWA审核对照  JOB 计算错误 " + e.getMessage());
		} finally {
			dmHcpmsEwOrgKpiDFDAO.insertEtlBatchJobLogDTO(obj);
			if (count > 0) {
				dmHcpmsEwOrgKpiDFDAO.updateDmHcpmsEwBct1KpiMF(pczt);
			}
		}
	}

	/***
	 * 医保总费用和处方数
	 * 
	 * @param dto
	 */
	private void addDMHcpmsEwAssCfMF(HcpmsBiEtlBatchDTO dto) {

		HcpmsBiEtlBatchLog obj = new HcpmsBiEtlBatchLog();
		obj.setBatchNo(dto.getBatchNo());
		obj.setOpertionName("医保总费用和处方数 JOB");
		obj.setOpertionDesc("医保总费用和处方数  JOB");

		Map<String, String> pczt = new HashMap<String, String>();
		pczt.put("idEtlBatch", dto.getIdEtlBatch());
		// 状态(00未处理 01抽取中 02抽取完成 20抽取失败)
		pczt.put("status", "20");
		int count = 0;
		try {

			dmHcpmsEwOrgKpiDFDAO.insertDMHcpmsEwAssCfMFMz(getStrDateAndEndDate(dto, null, null, null));
			dmHcpmsEwOrgKpiDFDAO.insertDMHcpmsEwAssCfMFZy(getStrDateAndEndDate(dto, null, null, null));

		} catch (Exception e) {
			count++;
			obj.setStatus("02");// 失败
			obj.setExceptionMessage("报异常:" + e.getMessage());
			log.info("医保总费用和处方数  JOB 计算错误 " + e.getMessage());
		} finally {
			dmHcpmsEwOrgKpiDFDAO.insertEtlBatchJobLogDTO(obj);
			if (count > 0) {
				dmHcpmsEwOrgKpiDFDAO.updateDmHcpmsEwBct1KpiMF(pczt);
			}
		}
	}

	/******************* 421 ********************/
	/***
	 * BI报表数据项统计信息表 2015-04-07
	 * 
	 * @param dto
	 */
	private void addDmBiAllKpiValues(HcpmsBiEtlBatchDTO dto) {

		HcpmsBiEtlBatchLog obj = new HcpmsBiEtlBatchLog();
		obj.setBatchNo(dto.getBatchNo());
		obj.setOpertionName("BI报表数据项统计信息表 JOB");
		obj.setOpertionDesc("BI报表数据项统计信息表  JOB");

		Map<String, String> pczt = new HashMap<String, String>();
		pczt.put("idEtlBatch", dto.getIdEtlBatch());
		// 状态(00未处理 01抽取中 02抽取完成 20抽取失败)
		pczt.put("status", "20");
		int count = 0;
		try {
			// 住院
			Map<String, Object> map1 = getStrDateAndEndDate(dto, null, "1", "Zy");
			dmHcpmsEwOrgKpiDFDAO.insertDmBiAllKpiValues(map1);

			// 门诊
			Map<String, Object> map2 = getStrDateAndEndDate(dto, null, "2", "Mz");
			dmHcpmsEwOrgKpiDFDAO.insertDmBiAllKpiValues(map2);

			// 修改 门诊转住院人次
			dmHcpmsEwOrgKpiDFDAO.insertDmBiAllKpiVluesMZZZYRC(getStrDateAndEndDate(dto, null, null, null));
		} catch (Exception e) {
			count++;
			obj.setStatus("02");// 失败
			obj.setExceptionMessage("报异常:" + e.getMessage());
			log.info("BI报表数据项统计信息表  JOB 计算错误 " + e.getMessage());
		} finally {
			dmHcpmsEwOrgKpiDFDAO.insertEtlBatchJobLogDTO(obj);
			if (count > 0) {
				dmHcpmsEwOrgKpiDFDAO.updateDmHcpmsEwBct1KpiMF(pczt);
			}
		}
	}

	/***
	 * 修改 BI报表数据项统计信息表中的住院天数 2015-04-07
	 * 
	 * @param dto
	 */
	private void updateDmBiAllKpiValuesHospitolDay(HcpmsBiEtlBatchDTO dto) {

		HcpmsBiEtlBatchLog obj = new HcpmsBiEtlBatchLog();
		obj.setBatchNo(dto.getBatchNo());
		obj.setOpertionName("修改 BI报表数据项统计信息表中的住院天数 JOB");
		obj.setOpertionDesc("修改 BI报表数据项统计信息表中的住院天数  JOB");

		Map<String, String> pczt = new HashMap<String, String>();
		pczt.put("idEtlBatch", dto.getIdEtlBatch());
		// 状态(00未处理 01抽取中 02抽取完成 20抽取失败)
		pczt.put("status", "20");
		int count = 0;

		try {
			// 修改住院天数
			dmHcpmsEwOrgKpiDFDAO.updateDmBiAllKpiValuesHospitolDay(getStrDateAndEndDate(dto, null, null, null));
			// 机构人数人次表
			dmHcpmsEwOrgKpiDFDAO.insertDmHcpmsEwProtocOrgPerson(getStrDateAndEndDate(dto, null, null, null));
			// 科室人数人次表
			dmHcpmsEwOrgKpiDFDAO.insertDmHcpmsEwProtocDeptPerson(getStrDateAndEndDate(dto, null, null, null));

			/*
			 * // 插入住院重复人数 dmHcpmsEwOrgKpiDFDAO.insertDmBiAllKpiValuesPCCFRS(
			 * getStrDateAndEndDate(dto, null, "1", "Zy")); // // 插入门诊重复人数
			 * dmHcpmsEwOrgKpiDFDAO
			 * .insertDmBiAllKpiValuesPCCFRS(getStrDateAndEndDate(dto, null,
			 * "2", "Mz"));
			 * 
			 * // 修改 统计重复住院人数
			 * dmHcpmsEwOrgKpiDFDAO.updateDmBiAllKpiValuesRrpeatHospitolNum
			 * (getStrDateAndEndDate(dto, null, null, null));
			 */

		} catch (Exception e) {
			count++;
			obj.setStatus("02");// 失败
			obj.setExceptionMessage("报异常:" + e.getMessage());
			log.info("修改 BI报表数据项统计信息表中的住院天数  JOB 计算错误 " + e.getMessage());
		} finally {
			dmHcpmsEwOrgKpiDFDAO.insertEtlBatchJobLogDTO(obj);
			if (count > 0) {
				dmHcpmsEwOrgKpiDFDAO.updateDmHcpmsEwBct1KpiMF(pczt);
			}
		}
	}

	/***
	 * 机构和科室基础指标表 2015-04-07
	 * 
	 * @param dto
	 */
	private void addDmHcpmsEwProtocOrgKpiF(HcpmsBiEtlBatchDTO dto) {

		HcpmsBiEtlBatchLog obj = new HcpmsBiEtlBatchLog();
		obj.setBatchNo(dto.getBatchNo());
		obj.setOpertionName("机构基础指标表 JOB");
		obj.setOpertionDesc("机构基础指标表  JOB");

		Map<String, String> pczt = new HashMap<String, String>();
		pczt.put("idEtlBatch", dto.getIdEtlBatch());
		// 状态(00未处理 01抽取中 02抽取完成 20抽取失败)
		pczt.put("status", "20");
		int count = 0;

		try {
			// 机构 医保
			Map<String, Object> map1 = getStrDateAndEndDate(dto, "10002", null, null);
			dmHcpmsEwOrgKpiDFDAO.insertDmHcpmsEwProtocOrgKpiFMzYb(map1);

			// 机构 医疗
			Map<String, Object> map2 = getStrDateAndEndDate(dto, "10001", null, null);
			dmHcpmsEwOrgKpiDFDAO.insertDmHcpmsEwProtocOrgKpiFMzYl(map2);

			// 机构 、科室 医疗
			Map<String, Object> map3 = getStrDateAndEndDate(dto, "10001", null, null);
			dmHcpmsEwOrgKpiDFDAO.insertDmHcpmsEwProtocDeptKpiFYl(map3);
			// 机构 、科室 医保
			Map<String, Object> map4 = getStrDateAndEndDate(dto, "10002", null, null);
			dmHcpmsEwOrgKpiDFDAO.insertDmHcpmsEwProtocDeptKpiFYb(map4);

		} catch (Exception e) {
			count++;
			obj.setStatus("02");// 失败
			obj.setExceptionMessage("报异常:" + e.getMessage());
			log.info("机构基础指标表  JOB 计算错误 " + e.getMessage());
		} finally {
			dmHcpmsEwOrgKpiDFDAO.insertEtlBatchJobLogDTO(obj);
			if (count > 0) {
				dmHcpmsEwOrgKpiDFDAO.updateDmHcpmsEwBct1KpiMF(pczt);
			} else {
				log.info("-----修改 etl 批次数据 状态-----");
				// 状态(00未处理 01抽取中 02抽取完成 20抽取失败)
				pczt.put("status", "02");
				dmHcpmsEwOrgKpiDFDAO.updateDmHcpmsEwBct1KpiMF(pczt);
			}
		}
	}

	/***
	 * 参数组装
	 * 
	 * @param dto
	 * @param ylOrYb
	 * @return
	 * @throws ParseException
	 */
	public Map<String, Object> getStrDateAndEndDate(HcpmsBiEtlBatchDTO dto, String ylOrYb, String visittype,
			String ZyOrMz) throws Exception {

		Map<String, Object> map = new HashMap<String, Object>();
		// 根据预警期 求月份开始和结束时间

		SimpleDateFormat sft = new SimpleDateFormat("yyyy-MM");
		Date date = sft.parse(dto.getMonth());

		map.put("batchNo", dto.getBatchNo());
		map.put("month", dto.getMonth().replace("-", ""));

		Calendar cal = Calendar.getInstance();
		cal.setTime(date);
		map.put("strDate", cal.getTime());

		cal.add(Calendar.MONTH, 1);
		cal.add(Calendar.MILLISECOND, -1);
		map.put("endDate", cal.getTime());

		map.put("regionCode", dto.getRegionCode());

		if (null != ylOrYb && !ylOrYb.equals("")) {
			if (ylOrYb.equals("10001")) {

				map.put("totalChargeType", "10001");
			} else if (ylOrYb.equals("10002")) {

				map.put("totalChargeType", "10002");
			}
		}
		if (null != visittype && !visittype.equals("")) {
			if (visittype.equals("1")) {
				map.put("visittype", "1");
			}
			if (visittype.equals("2")) {
				map.put("visittype", "2");
			}
		}
		if (null != ZyOrMz && !ZyOrMz.equals("")) {
			if (ZyOrMz.equals("Zy")) {
				map.put("Zy", "Zy");
			}
			if (ZyOrMz.equals("Mz")) {
				map.put("Mz", "Mz");
			}
		}

		return map;
	}

}
